package com.learn.yu.proxy.dynamic.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author : Yu.Tan
 * @date : 2023/6/21 16:37
 * @desc : **
 */
public class InvocationHandlerSubject implements InvocationHandler {

    private Object subject;

    public InvocationHandlerSubject(Object subject){
        this.subject=subject;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("Proxy Before：JDK代理前添加自己操作");
        // 当代理对象调用真实对象的方法时，其会自动的跳转到代理对象关联的handler对象的invoke方法来进行调用
        Object invoke = method.invoke(subject, args);
        System.out.println("Proxy After：JDK代理后添加自己操作");
        return invoke;
    }

}
